"""
Base class for World, Scene, and others.
"""

from GameObjectListener import *

class GameObject(object):
    def __init__(self, pathResolver):
        self.listeners = {"OnFinish": [],
                          "OnStart":  []}
        self.pathResolver = pathResolver
    def addListener(self, event, script):
        l = GameObjectListener(self, self.pathResolver.findFile(script))
        # Create key if it does not exist.
        if (event not in self.listeners):
            self.listeners[event] = []
        self.listeners[event].append(l)
    def call(self, event):
        for listener in self.listeners[event]:
            listener.module.run(listener)
    def finish(self):
        self.call("OnFinish")
    def start(self):
        self.call("OnStart")
